// ignore: must_be_immutable
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:ost_flutter_module/common/adapt.dart';
import 'package:ost_flutter_module/common/color.dart';
import 'package:ost_flutter_module/common/styles.dart';
import 'package:ost_flutter_module/common/utils.dart';
import 'package:ost_flutter_module/widget/custom_widget/custome_bottom_button.dart';
import 'package:ost_flutter_module/widget/custom_widget/custome_list_tile.dart';
import 'package:ost_flutter_module/widget/custom_widget/custome_radius_container.dart';
import 'package:ost_flutter_module/widget/custom_widget/custome_shape.dart';
import 'package:ost_flutter_module/widget/custom_widget/custome_size_icon_button.dart';
import 'package:ost_flutter_module/widget/custom_widget/sliver_footer.dart';

class StoreDiscountPageBody extends StatelessWidget {
  List _list = [
    '1', '2', '2',
    // ShopCartEntity(
    //     id: '0',
    //     name: '发音口肌专家课',
    //     no: '1次',
    //     addr: '深圳金田中心',
    //     tags: [ShopCartTagEntity(name: '特惠'), ShopCartTagEntity(name: '精选')],
    //     price: '￥1800'),
    // ShopCartEntity(id: '1', name: '认知卡片5种颜色', price: '￥36'),
  ];
  @override
  Widget build(BuildContext context) {
    return GBottomButton(
      children: [
        ListView.builder(
          itemCount: _list.length,
          itemBuilder: (BuildContext context, int index) {
            // ShopCartEntity entity = _list[index];

            // 底部增加一个空item
            if (index == _list.length - 1) {
              return SliverFooter();
            }

            if (index == 0) {
              return GContainer(
                child: GListTile(
                  text: '不使用优惠券',
                  enable: true,
                  enableWidget: Utils.svgAssets('icon_unselected'),
                ),
              );
            }
            return StoreDiscountPageBodyCard();
          },
        ),
      ],
      title: '确定',
      onPressed: () {
        Navigator.pop(context);
      },
    );
  }
}

class StoreDiscountPageBodyCard extends StatelessWidget {
  final int row;
  final bool check;
  // final ShopCartEntity entity;
  final ValueChanged<dynamic> onPressed;

  const StoreDiscountPageBodyCard(
      {Key key, this.row, this.check, this.onPressed})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.zero,
      child: GContainer(
        // color: Colors.white,
        color: colorFAFAFA,
        height: Adapt.px(100),
        shape: CouponShapeBorder(),
        child: _buildCard(),
      ),
    );
  }

  Widget _buildCard() {
    return Row(
      children: [
        Container(
          // color: colorFACD33,
          width: Adapt.px(100),
          height: Adapt.px(100),
          child: Center(
            child: RichText(
                text: TextSpan(
              text: '￥',
              style: TextStyle(fontSize: 10, color: color42270C),
              children: [
                TextSpan(
                    text: '500',
                    style: TextStyle(
                      fontSize: 20,
                      fontWeight: FontWeight.bold,
                      color: color42270C,
                    ))
              ],
            )),
          ),
        ),
        SizedBox(width: Adapt.px(16)),
        Expanded(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text('全勤优惠券', style: TextStyles.titleStyle),
              SizedBox(height: Adapt.px(8)),
              Text('有效期：2021-03-30', style: TextStyles.detailTitleStyle),
              SizedBox(height: Adapt.px(8)),
              Text('可叠加使用', style: TextStyles.detailTitleStyle),
            ],
          ),
        ),
        GIconButton(
          svg: Utils.svgAssets('icon_unselected'),
          onPressed: () => onPressed(EditAddress.edit),
        ),
      ],
    );
  }
}

class DiscountClipper extends CustomClipper<Path> {
  @override
  getClip(Size size) {
    var path = Path();

    double border = Adapt.px(10);
    double outBorder = Adapt.px(20);
    double lineRate = 100;

    /// 355;

    path.moveTo(0, 0);
    path.lineTo(lineRate, 0);
    // path.relativeQuadraticBezierTo(
    //     lineRate, outBorder, lineRate + outBorder * 2, 0);
    path.arcTo(
        Rect.fromCenter(
            center: Offset(lineRate + outBorder, 0),
            width: outBorder * 2,
            height: outBorder * 2),
        0,
        pi / 2,
        false);
    path.lineTo(size.width, 0);
    path.lineTo(size.width, size.height + 5);
    path.lineTo(0, size.height + 5);

    // path.quadraticBezierTo(0, border, 0, size.height - border);

    // path.addArc(
    //     Rect.fromCenter(
    //         center: Offset(Adapt.px(lineRate), 0),
    //         width: Adapt.px(20.0),
    //         height: Adapt.px(20.0)),
    //     0,
    //     pi);

    return path;
  }

  @override
  bool shouldReclip(covariant CustomClipper oldClipper) {
    return true;
  }
}
